package com.yazi.mxz.common.db.dao.impl;


import java.util.HashMap;
import java.util.Map;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.stereotype.Repository;

import com.myframework.smhj.hibernate.dao.BasicDao;
import com.yazi.mxz.common.db.dao.MemberPromoteDao;
import com.yazi.mxz.common.entity.beans.Company;
import com.yazi.mxz.common.entity.beans.MemberPromote;

@Repository("memberPromoteDao")
public class MemberPromoteDaoImpl extends BasicDao<MemberPromote> implements MemberPromoteDao {


	public MemberPromoteDaoImpl() {
		super(MemberPromote.class);
		
	}

	@Override
	public Criteria getExample(MemberPromote mp, String searchWord) {
		Criteria c = super.getExample(mp, searchWord);
		
		// 关联对象条件
		if (null != mp) {
			// 企业
			Company company = mp.getCompany();
			if (null !=  company) {
				// 企业ID
				if (null != company.getCompanyId()) {
					c.add(Restrictions.eq("company.companyId", company.getCompanyId()));
				} else {
					// ...企业其它条件
				}
			}
			// ...其它关联对象条件
		}
		
		// ...关键字searchWord条件
		return c;
	}
	
	@Override
	public int delete(long companyId, int type) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("companyId", companyId);
		map.put("type", type);
		return executeUpdate("delByCompanyIdTypeHql", map);
	}

	@Override
	public MemberPromote oneFloorPrepaid(long companyId, int type, float prepaid) {
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("companyId", companyId);
		map.put("type", type);
		map.put("prepaid", prepaid);
		return unique("listFloorPrepaidHql", map);
	}
	
}
